import { asyncRoutes, constantRoutes } from '@/router'

const state = {
  routes: []
}
const mutations = {
  setRoutes(state, payload) {
    state.routes = [...constantRoutes, ...payload]
  }
}
const actions = {
  filterRoutes(context, menus) {
    console.log('拿到权限列表', menus)
    console.log('引入的动态路由列表', asyncRoutes)
    const res = []
    asyncRoutes.forEach(item => {
      // 权限列表筛选
      if (menus.indexOf(item.name) !== -1) {
        res.push(item)
      }
      // if (menus.indexOf(item.name)) {
      //   res.push(item)
      // }
    })
    console.log('筛选过后路由列表', res)
    context.commit('setRoutes', res)
    return res
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
